package com.ruoyi.common.utils.pay.controller;

import com.ruoyi.common.cyzUtils.OrderPrefix;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.Map;

@RestController
@Component
public class Common{

    @Transactional(rollbackFor = Exception.class)
    public void result(String out_trade_no, Map<String, String> params) throws Exception {

//    订单状态变更后

//平台商品价格       1000  实际

        // 1.0

//        上级分佣 parent_id  0.01   user_id

//        销售分成 sell_user_id 0.05

//        平台 1000 0.94

        /*
        try {

            if (StringUtil.isNotEmpty(out_trade_no)) {
                System.out.println("接受回调>>>>>>>>>---------------------------------");
                if (out_trade_no.startsWith("DD")) {
                    System.out.println("--------------------------------->>>>>>>>>订单");
                    Order order = orderService.selectOrderById(out_trade_no);
                    if (order == null) throw new Exception("支付日志错误");
                    if (order.getStatus() == 1) {
                        order.setStatus(2);
                        orderService.updateOrder(order);
                        System.out.println("--------------------------------->>>>>>>>>回调成功");
                    }
                }
                if (out_trade_no.startsWith("CZ")) {
                    System.out.println("--------------------------------->>>>>>>>>充值");
                    Recharge order = rechargeService.selectRechargeByOrdnum(out_trade_no);
                    if (order == null) throw new Exception("支付日志错误");
                    if (order.getStatus() == 1) {
                        order.setStatus(2);
                        rechargeService.updateRecharge(order);
                        flowService.insertFlow(new FlowUtil(null, order.getUserId(), order.getGiveMoney(), 0, "微信充值" + order.getOrdnum()).getFlow());
                        System.out.println("--------------------------------->>>>>>>>>回调成功");
                    }
                }
                if (out_trade_no.startsWith("DS")) {
                    System.out.println("--------------------------------->>>>>>>>>打赏");
                    Recharge order = rechargeService.selectRechargeByOrdnum(out_trade_no);
                    if (order == null) throw new Exception("支付日志错误");
                    if (order.getStatus() == 1) {
                        order.setStatus(2);
                        rechargeService.updateRecharge(order);
                        Order temp = orderService.selectOrderById(out_trade_no.replaceFirst("DS","DD"));
                        temp.setMarkAward(1);
                        orderService.updateOrder(temp);
                        flowService.insertFlow(new FlowUtil(null, temp.getServe().getUserId(), order.getGiveMoney(), 0, "微信打赏" + temp.getOrdnum()).getFlow());
                        System.out.println("--------------------------------->>>>>>>>>回调成功");
                    }
                }
            }
        } catch (Exception e) {
            throw new Exception("--------------------------------->>>>>>>>>回调失败");
        }
        */
    }
}
